//
//  RDVTabBarControllerConfig.m
//  C2CMember
//
//  Created by yangy on 2018/8/10.
//  Copyright © 2018年 iphone. All rights reserved.
//

#import "RDVTabBarControllerConfig.h"
// controller
// controller
#import "AM_HomeViewController.h"
#import "AM_MarketViewController.h"
#import "AM_TradeViewController.h"
#import "AM_LegalViewController.h"
#import "AM_TreatyViewController.h"
#import "CM_NavigationViewController.h"
#import "RDVTabBarItem.h"

@interface RDVTabBarControllerConfig()
@property (nonatomic, strong) AM_HomeViewController *homeVC;     // 首页
@property (nonatomic, strong) AM_MarketViewController *marketVC; // 行情
@property (nonatomic, strong) AM_TradeViewController *tradeVC;   // 币币交易
@property (nonatomic, strong) AM_LegalViewController *legalVC;   // 法币交易
@property (nonatomic, strong) AM_TreatyViewController *treatVC;  // 合约交易
@end

@implementation RDVTabBarControllerConfig

- (RDVTabBarController *)tabbarController
{
    if(!_tabbarController){
        CM_NavigationViewController *nav1 = [[CM_NavigationViewController alloc] initWithRootViewController:self.homeVC];
        CM_NavigationViewController *nav2 = [[CM_NavigationViewController alloc] initWithRootViewController:self.marketVC];
        CM_NavigationViewController *nav3 = [[CM_NavigationViewController alloc] initWithRootViewController:self.tradeVC];
        CM_NavigationViewController *nav4 = [[CM_NavigationViewController alloc] initWithRootViewController:self.legalVC];
        CM_NavigationViewController *nav5 = [[CM_NavigationViewController alloc] initWithRootViewController:self.treatVC];
        
       _tabbarController = [[RDVTabBarController alloc] init];
        [_tabbarController setViewControllers:@[nav1, nav2,
                                               nav3,nav4,nav5]];
        [self customizeTabBarForController:_tabbarController];
    }
    return _tabbarController;
}

- (void)customizeTabBarForController:(RDVTabBarController *)tabBarController {
    UIImage *finishedImage = [UIImage imageNamed:@"tabbar_selected_background"];
    UIImage *unfinishedImage = [UIImage imageNamed:@"tabbar_normal_background"];
    NSArray *tabBarItemImages = @[@"tabbar_home", @"tabbar_market", @"tabbar_trade",@"tabbar_legal",@"tabbar_treaty"];
    
    NSInteger index = 0;
    for (RDVTabBarItem *item in [[tabBarController tabBar] items]) {
        [item setBackgroundSelectedImage:finishedImage withUnselectedImage:unfinishedImage];
        UIImage *selectedimage = [UIImage imageNamed:[NSString stringWithFormat:@"%@_sel",
                                                      [tabBarItemImages objectAtIndex:index]]];
        UIImage *unselectedimage = [UIImage imageNamed:[NSString stringWithFormat:@"%@_nor",
                                                        [tabBarItemImages objectAtIndex:index]]];
        [item setFinishedSelectedImage:selectedimage withFinishedUnselectedImage:unselectedimage];
        
        index++;
    }
}

- (AM_HomeViewController *)homeVC
{
    if(!_homeVC){
        _homeVC = [[AM_HomeViewController alloc] init];
        _homeVC.title = @"首页";
//        _homeVC.tabBarItem.selectedImage = [UIImage imageNamed:@"tabbar_home_sel"];
//        _homeVC.tabBarItem.image = [UIImage imageNamed:@"tabbar_home_nor"];
    }
    return _homeVC;
}

- (AM_MarketViewController *)marketVC
{
    if(!_marketVC){
        _marketVC = [[AM_MarketViewController alloc] init];
        _marketVC.title = @"行情";
//        _marketVC.tabBarItem.selectedImage = [UIImage imageNamed:@"tabbar_market_sel"];
//        _marketVC.tabBarItem.image = [UIImage imageNamed:@"tabbar_market_nor"];
    }
    return _marketVC;
}

- (AM_TradeViewController *)tradeVC
{
    if(!_tradeVC){
        _tradeVC = [[AM_TradeViewController alloc] init];
        _tradeVC.title = @"币币";
//        _tradeVC.tabBarItem.selectedImage = [UIImage imageNamed:@"tabbar_trade_sel"];
//        _tradeVC.tabBarItem.image = [UIImage imageNamed:@"tabbar_trade_nor"];
    }
    return _tradeVC;
}

- (AM_LegalViewController *)legalVC
{
    if(!_legalVC){
        _legalVC = [[AM_LegalViewController alloc] init];
        _legalVC.title = @"法币";
//        _legalVC.tabBarItem.selectedImage = [UIImage imageNamed:@"tabbar_legal_sel"];
//        _legalVC.tabBarItem.image = [UIImage imageNamed:@"tabbar_legal_nor"];
    }
    return _legalVC;
}

- (AM_TreatyViewController *)treatVC
{
    if(!_treatVC){
        _treatVC = [[AM_TreatyViewController alloc] init];
        _treatVC.title = @"合约";
//        _treatVC.tabBarItem.selectedImage = [UIImage imageNamed:@"tabbar_treaty_sel"];
//        _treatVC.tabBarItem.image = [UIImage imageNamed:@"tabbar_treaty_nor"];
    }
    return _treatVC;
}


@end
